package cn.winwintech.Incense.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.base.webapp.persist.Persistence;

import cn.winwintech.Incense.dao.GenericDao;

@Repository
public class GenericDaoImpl implements GenericDao {

	@Autowired
	protected Persistence persistence;

	@Override
	public void save(Object e) {
		persistence.save(e);
	}

	@Override
	public <T> T findSingle(Class<T> modelClass, String fieldName, Object fieldValue) {
		return persistence.findSingle(modelClass, fieldName, fieldValue);
	}

	@Override
	public void delete(Object e) {
		persistence.delete(e);
	}

	@Override
	public <T> List<T> find(Class<T> modelClass) {
		return persistence.find(modelClass);
	}

	@Override
	public <T> T find(Class<T> class1, Object id) {
		return persistence.find(class1, id);
	}

	@Override
	public int getTotalPage(int pageSize, int totalCount) {
		return totalCount / pageSize + (totalCount % pageSize == 0 ? 0 : 1);
	}

}
